#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Richard_Kong
import unittest
from parameterized import parameterized
from api.LogInAPI import LogInAPI
import requests
from tools.HTMLTestRunner import HTMLTestRunner

"""
写测试脚本的套路，根据套路先写出骨架代码
1、# 导包
2、定义测试类
3、写前后置函数
4、写测试用例函数
test_learn
更改代码验证git pull
<<<<<<< HEAD
更改3
更改4冲突问题本地工作区
冲突更改问题
>>>>>>> 7d47649e8a3347acda76bd37184d95efb575e220
"""
from common.readjson import read_json_para
from common.common_assert import common_assert
test_data = read_json_para()


class Test_Login(unittest.TestCase):
    def setUp(self) -> None:
        """
        在方法级fixture中创建session
        :return: None
        """
        self.session = requests.Session()
        self.loginapi = LogInAPI()
        print("test_learn")
        pass

    def tearDown(self) -> None:
        if self.session:
            self.session.close()
        pass

    @parameterized.expand(test_data)
    def test01_login_sucess(self, login_data, success, code, message):
        """
        登陆IHRM 获取token信息
        :return:
        """
        response = self.loginapi.login(self.session, login_data)

        common_assert(self,response,success,code,message)
        # self.assertEqual(200,response.status_code)
        # self.assertEqual(success, response.json().get("success"))
        # self.assertEqual(code, response.json().get('code'))
        # self.assertEqual(message, response.json().get("message"))


        # self.assertEqual(True,response.json().get("success"))
        # self.assertEqual(10000,response.json().get('code'))
        # self.assertEqual("操作成功！",response.json().get("message"))
        # config.login_token_data = response.json().get("data")
        # print(config.login_token_data)


if __name__ == '__main__':
    test_suit = unittest.TestSuite()
    test_suit.addTest(unittest.makeSuite(Test_Login))
    report = "./report.html"
    with open(file=report,mode='wb') as f:
        runner = HTMLTestRunner(stream=f, title="test_report")
        runner.run(test_suit)
